﻿@model Inovout.Kuajing.Exports.Console.Web.Models.ConsigneeInfo
@{
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}

@section styles {
    <link href="~/Content/themes/base/autocomplete.css" rel="stylesheet" />
    <style>
        .form form {
            margin: 20em auto;
        }

        #header_h3 {
            margin-top: 10px;
        }

        .consigneeForm {
            margin-top: 3em;
        }

            .consigneeForm select {
                max-width: 280px;
            }
    </style>
}


@section scriptsHead {
    <script>

        $(document).ready(function () {

            $.validator.setDefaults({ ignore: "" });

            if (!$("#CommpanyCode").val()) {
                $("#CommpanyCode").val(0);
            }

            if (!$("#ContactPersonCode").val()) {
                $("#ContactPersonCode").val(0);
            }

            $("#CommpanyName").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: '@Url.Action("FilterOrganiziation", "OrganizationUnit")',
                        type: "POST",
                        dataType: "json",
                        data: { term: request.term },
                        success: function (data) {
                            response($.map(data, function (item) {
                                return {
                                    label: item.label,
                                    value: item.value,
                                    location: item.location
                                };
                            }))
                        }
                    })
                },
                focus: function (event, ui) {
                    $("#CommpanyName").val(ui.item.label);
                    return false;
                },
                minLength: 2,
                select: function (event, ui) {
                    $("#CommpanyName").val(ui.item.label);
                    $("#CommpanyCode").val(ui.item.value);
                    //设置下拉列表
                    $("#Country").val(ui.item.location);
                    LoadConsignee(ui.item.value);
                    return false;
                }
            });

            //设置交易方的地址
            var PageManager = {};
            var LoadConsignee = function (organizationId) {
                $.ajax({
                    url: '@Url.Action("FindConsigee", "Consignee")',
                    type: "POST",
                    dataType: "json",
                    data: { Id: organizationId },
                    success: function (data) {
                        $("#Address").val(data.address);
                        $("#ConsigneeCode").val(data.id);
                    },
                    error: function (jqXHR, textStatus, errorThrown) {

                    }
                })
            };

            $("#Address").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: '@Url.Action("FilterConsigee", "Consignee")',
                        type: "POST",
                        dataType: "json",
                        data: { term: request.term, Id: $("#CommpanyCode").val() },
                        success: function (data) {
                            response($.map(data, function (item) {
                                return {
                                    label: item.label,
                                    value: item.value
                                };
                            }))
                        }
                    })
                },
                focus: function (event, ui) {
                    $("#Address").val(ui.item.label);
                    return false;
                },
                minLength: 2,
                select: function (event, ui) {
                    debugger;
                    $("#Address").val(ui.item.label);
                    $("#ConsigneeCode").val(ui.item.value);
                    return false;
                }
            });

            $("#ContactPersonName").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: '@Url.Action("FilterEmployee", "Employee")',
                        type: "POST",
                        dataType: "json",
                        data: { term: request.term, Id: $("#CommpanyCode").val() },
                        success: function (data) {
                            response($.map(data, function (item) {
                                return {
                                    label: item.label,
                                    value: item.value,
                                    phone: item.phone
                                };
                            }))

                        }
                    })
                },
                focus: function (event, ui) {
                    $("#ContactPersonName").val(ui.item.label);
                    return false;
                },
                minLength: 2,
                select: function (event, ui) {
                    debugger;
                    $("#ContactPersonName").val(ui.item.label);
                    $("#ContactPersonCode").val(ui.item.value);
                    $("#ContactPhone").val(ui.item.phone);
                    return false;
                }
            });
        });

    </script>

}



@{
    <h3 id="header_h3">
        <label>出口商名称：</label>
        <strong>@ViewBag.ExporterName</strong>
        <label>下单人名称：</label><strong>@ViewBag.OrderPersonName</strong></h3>
}

<div>

    @using (Html.BeginForm("LocateConsignee", "TraditionalOrder", FormMethod.Post, new { @class = "form-horizontal consigneeForm" }))
    { 
         @Html.ValidationSummary(true)
        <div class="form-group">
            @Html.LabelFor(model => model.CommpanyName, "收货人", new { @for = "CommpanyName", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(mode => mode.CommpanyName, new { @placeholder = "南京三宝", @class = "form-control" })
                @Html.HiddenFor(model => model.CommpanyCode, new { @value = "0" })
                @Html.HiddenFor(model => model.CommpanyName, new { @name = "hdCommanyName" })
                @Html.HiddenFor(model => model.OrderId)
                @Html.ValidationMessageFor(model => model.CommpanyName)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Country, "国家", new { @for = "Country", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.Country, (SelectList)ViewData["countries"], new { @class = "form-control" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Address, "详细地址", new { @for = "Address", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(mode => mode.Address, new { @placeholder = "xxxx街二号", @class = "form-control" })
                @Html.HiddenFor(model => model.ConsigneeCode, new { @value = "0" })
                @Html.ValidationMessageFor(model => model.Address)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.ContactPersonName, "联系人", new { @for = "ContactPersonName", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(mode => mode.ContactPersonName, new { @placeholder = "联系人", @class = "form-control" })
                @Html.HiddenFor(model => model.ContactPersonCode, new { @value = "0" })
                @Html.ValidationMessageFor(model => model.ContactPersonName)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.ContactPhone, "电话", new { @for = "ContactPhone", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(mode => mode.ContactPhone, new { @placeholder = "13565254526", @class = "form-control" })
                @Html.ValidationMessageFor(model => model.ContactPhone)
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="submit" id="export" class="btn btn-default" value="下一步" />
            </div>
        </div>

    }
</div>
